package com.ruoyi.web.controller.data;

import com.google.gson.Gson;
import com.ruoyi.bus.domain.map.BusMessage;
import com.ruoyi.bus.service.IDataService;
import com.ruoyi.bus.springutil.SpringUtils;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @Description 班车预约数据通用
 * @Author caiyanshan
 * @Date 2021/5/28 9:54
 * @Param
 * @Return
 */
@RestController
@RequestMapping("/data")
public class CommonDataController {
  
  @Autowired
  private IDataService dataService;
  
  @GetMapping("getData")
  public AjaxResult getData(){
    Map<String, Object> paramMap = new HashMap<String, Object>();
    paramMap.put("routeCount", this.getRouteCount());
    paramMap.put("busCount", this.getBusCount());
    paramMap.put("driverCount", this.getDriverCount());
    paramMap.put("userCount", this.getUserCount());
    paramMap.put("todayAppointCount", this.getTodayAppointCount());
    paramMap.put("userNotRegister", this.getUserNotRegister());
    return AjaxResult.success(paramMap);
  }
  
  /**
   * @Description 中间分数段数据
   * @Author caiyanshan
   * @Date 2021/6/7 15:39
   * @Param []
   * @Return com.ruoyi.common.core.domain.AjaxResult
   */
  @GetMapping("getFractionData")
  public AjaxResult getFractionData(){
    Map<String, Object> paramMap = new HashMap<String, Object>();
    
    Map<String, Object> planProp = new HashMap<String, Object>();
    planProp.put("driverCount", this.getDriverCount());
    planProp.put("planCount", this.getPlanCountByDays());
    paramMap.put("planProp", planProp);
  
    Map<String, Object> appointProp = new HashMap<String, Object>();
    appointProp.put("userCount", this.getUserCount());
    appointProp.put("appointCount", this.getTodayAppointCount());
    paramMap.put("appointProp", appointProp);
  
    Map<String, Object> rideProp = new HashMap<String, Object>();
    rideProp.put("appointOverCount", this.getTodayAppointOverCount());
    rideProp.put("appointCount", this.getTodayAppointCount());
    paramMap.put("rideProp", rideProp);
  
    Map<String, Object> sendCarProp = new HashMap<String, Object>();
    sendCarProp.put("planOverCount", this.getPlanCountOverByDays());
    sendCarProp.put("planCount", this.getPlanCountByDays());
    paramMap.put("sendCarProp", sendCarProp);
    
    return AjaxResult.success(paramMap);
  }
  
  /**
   * @Description 按机构查询用户注册数据
   * @Author caiyanshan
   * @Date 2021/6/8 9:54
   * @Param []
   * @Return java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
   */
  @GetMapping("listSecondDeptByUsers")
  public AjaxResult listSecondDeptByUsers(){
    return AjaxResult.success(dataService.listSecondDeptByUsers());
  }
 
  
  /**
   * @Description 按日期分类查最近七天的排班数据
   * @Author caiyanshan
   * @Date 2021/6/7 14:51
   * @Param []
   * @Return com.ruoyi.common.core.domain.AjaxResult
   */
  @GetMapping("listPlanByDays")
  public AjaxResult listPlanByDays(@RequestParam Integer day){
    return AjaxResult.success(dataService.listPlanByDays(day));
  }
  
  /**
   * @Description 按日期分类查最近七天的预约数据
   * @Author caiyanshan
   * @Date 2021/6/7 14:42
   * @Param []
   * @Return com.ruoyi.common.core.domain.AjaxResult
   */
  @GetMapping("listAppointByDays")
  public AjaxResult listAppointByDays(@RequestParam Integer day){
    return AjaxResult.success(dataService.listAppointByDays(day));
  }
  
  /**
   * @Description 按日期分类查最近七天的已排班路线数据
   * @Author caiyanshan
   * @Date 2021/6/7 14:42
   * @Param []
   * @Return com.ruoyi.common.core.domain.AjaxResult
   */
  @GetMapping("listRouteByDays")
  public AjaxResult listRouteByDays(@RequestParam Integer day){
    return AjaxResult.success(dataService.listRouteByDays(day));
  }
  
  
  @GetMapping("getTodayAppointCountByCreateTime")
  public AjaxResult getTodayAppointCountByCreateTime(){
    return AjaxResult.success(dataService.getTodayAppointCountByCreateTime());
  }
  
  /**
   * @Description 预约数据按照机构排名
   * @Author caiyanshan
   * @Date 2021/6/3 14:40
   * @Param []
   * @Return java.util.List<java.util.Map<java.lang.String,java.lang.Integer>>
   */
  @GetMapping("listAppointCountByDept")
  public AjaxResult listAppointCountByDept(){
    return AjaxResult.success(dataService.listAppointCountByDept());
  }
  
  /**
   * @Description 列出预约数据最多的路线top10
   * @Author caiyanshan
   * @Date 2021/6/3 14:42
   * @Param []
   * @Return java.util.List<java.util.Map<java.lang.String,java.lang.Integer>>
   */
  @GetMapping("listMaxRouteByAppointTop10")
  public AjaxResult listMaxRouteByAppointTop10(){
    return AjaxResult.success(dataService.listMaxRouteByAppointTop10());
  }
  
  /**
   * @Description 列出预约数据最少的路线top10
   * @Author caiyanshan
   * @Date 2021/6/3 14:42
   * @Param []
   * @Return java.util.List<java.util.Map<java.lang.String,java.lang.Integer>>
   */
  @GetMapping("listMinRouteByAppointTop10")
  public AjaxResult listMinRouteByAppointTop10(){
    return AjaxResult.success(dataService.listMinRouteByAppointTop10());
  }
  
  /**
   * @Description 用户预约最多top50
   * @Author caiyanshan
   * @Date 2021/6/3 14:44
   * @Param []
   * @Return java.util.List<java.util.Map<java.lang.String,java.lang.Integer>>
   */
  @GetMapping("listMaxUserByAppointTop50")
  public AjaxResult listMaxUserByAppointTop50(){
    return AjaxResult.success(dataService.listMaxUserByAppointTop50());
  }
  
  /**
   * @Description 司机拍班数量top50
   * @Author caiyanshan
   * @Date 2021/6/4 9:02
   * @Param []
   * @Return java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
   */
  @GetMapping("listMaxDriverUserByPlanTop50")
  public AjaxResult listMaxDriverUserByPlanTop50(){
    return AjaxResult.success(dataService.listMaxDriverUserByPlanTop50());
  }
  
  /**
   * @Description 车辆历史数据列表
   * @Author caiyanshan
   * @Date 2021/7/26 10:35
   * @Param [json]
   * @Return java.lang.String
   */
  @GetMapping("listBus")
  public AjaxResult listBus(){
    return AjaxResult.success(SpringUtils.getBusService().listBusByLocationDays());
  }
  
  @GetMapping("listBusLocationByDays")
  public AjaxResult listBusLocationByDays(@RequestParam("createTime") String createTime,
                                          @RequestParam("busId") Long busId, @RequestParam("driveTime") String driveTime){
    Map<String, Object> paramMap = new HashMap<String, Object>();
    Date tempDate = null;
    try{
      tempDate = DateUtils.dateTime(DateUtils.YYYY_MM_DD, createTime);
    }catch(Exception e){
      return AjaxResult.error("日期转化出错，请核对日期格式");
    }
    paramMap.put("time", tempDate);
    paramMap.put("busId", busId);
    paramMap.put("driveTime", driveTime);
    return AjaxResult.success(SpringUtils.getLocationService().selectBusLocationByDays(paramMap));
  }
  
  /**
   * @Description 路线数
   * @Author caiyanshan
   * @Date 2021/6/3 14:36
   * @Param []
   * @Return int
   */
  public int getRouteCount(){
    return dataService.getRouteCount();
  }
  
  /**
   * @Description 司机数
   * @Author caiyanshan
   * @Date 2021/6/3 14:37
   * @Param []
   * @Return int
   */
  public int getDriverCount(){
    return dataService.getDriverCount();
  }
  
  public int getUserCount(){
    return dataService.getUserCount();
  }
  
  public int getUserNotRegister(){
    return dataService.getUserNotRegister();
  }
  
  public int getPlanCountOverByDays(){
    return dataService.getPlanCountOverByDays();
  }
  
  /**
   * @Description 车辆数
   * @Author caiyanshan
   * @Date 2021/6/3 14:37
   * @Param []
   * @Return int
   */
  public int getBusCount(){
    return dataService.getBusCount();
  }
  
  /**
   * @Description 今日预约数
   * @Author caiyanshan
   * @Date 2021/6/3 14:37
   * @Param []
   * @Return int
   */
  public int getTodayAppointCount(){
    return dataService.getTodayAppointCount();
  }
  
  public int getTodayAppointOverCount(){
    return dataService.getTodayAppointOverCount();
  }
  
  public int getPlanCountByDays(){
    return dataService.getPlanCountByDays();
  }
  
}
